﻿using ECO.Admin.Core.Shared.Enum.System;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ECO.Admin.Application.Controllers.Auth.Dtos.InputModels
{
    public class RegisterInput : ValidCodeInput, IValidatableObject
    {
        [DataValidation(ValidationTypes.EmailAddress, ErrorMessage = "邮件格式不正确")]
        public string Email { get; set; }

        [Required(ErrorMessage = "用户名不能为空")]
        public string UserName { get; set; }

        [DataValidation(ValidationTypes.PhoneOrTelNumber, ErrorMessage = "电话格式不正确")]
        public string Phone { get; set; }

        [StringLength(15, MinimumLength = 8, ErrorMessage = "密码长度最少6位,最长15位"), DataValidation(CustomValidationTypes.StrongPassword)]
        public string Password { get; set; }

        public string CheckPassword { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (Password != CheckPassword)
            {
                yield return new ValidationResult(
                    "两次密码输入不一致"
                    , new[] { nameof(Password) }  // 验证失败的属性
                );
            }
        }
    }
}
